const { sqlQuery } = require('../db/mysql')
const login = async (u, p) => {
  let sql = `select * from user where username='${u}' and password='${p}'`
  const res = await sqlQuery(sql)
  if (res.length > 0) {
    return res[0]
  } else false
}
const register = async (u, p, r) => {
  let sql = `insert into user (username,password, realname) values ('${u}', '${p}','${r}')`
  const res = await sqlQuery(sql)
  if (res.length > 0) {
    return res[0]
  } else false
}
const isExitUser = async (u) => {
  let sql = `select * from user where username='${u}'`
  const res = await sqlQuery(sql)
  if (res.length > 0) {
    return res[0]
  } else false
}
module.exports = {
  login,
  register,
  isExitUser,
}
